\doxysection{can\+\_\+comm.\+h}
\hypertarget{can__comm_8h_source}{}\label{can__comm_8h_source}\index{C:/Users/ASUS/Desktop/dm-\/ctrlH7-\/balance-\/9025test/modules/can\_comm/can\_comm.h@{C:/Users/ASUS/Desktop/dm-\/ctrlH7-\/balance-\/9025test/modules/can\_comm/can\_comm.h}}
\mbox{\hyperlink{can__comm_8h}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ }
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#ifndef\ CAN\_COMM\_H}}
\DoxyCodeLine{00012\ \textcolor{preprocessor}{\#define\ CAN\_COMM\_H}}
\DoxyCodeLine{00013\ }
\DoxyCodeLine{00014\ \textcolor{preprocessor}{\#include\ "{}bsp\_can.h"{}}}
\DoxyCodeLine{00015\ \textcolor{preprocessor}{\#include\ "{}daemon.h"{}}}
\DoxyCodeLine{00016\ }
\DoxyCodeLine{00017\ \textcolor{preprocessor}{\#define\ MX\_CAN\_COMM\_COUNT\ 4\ }\textcolor{comment}{//\ 注意均衡负载,一条总线上不要挂载过多的外设}}
\DoxyCodeLine{00018\ }
\DoxyCodeLine{00019\ \textcolor{preprocessor}{\#define\ CAN\_COMM\_MAX\_BUFFSIZE\ 60\ }\textcolor{comment}{//\ 最大发送/接收字节数,如果不够可以增加此数值}}
\DoxyCodeLine{00020\ \textcolor{preprocessor}{\#define\ CAN\_COMM\_HEADER\ 's'\ \ \ \ \ \ }\textcolor{comment}{//\ 帧头}}
\DoxyCodeLine{00021\ \textcolor{preprocessor}{\#define\ CAN\_COMM\_TAIL\ 'e'\ \ \ \ \ \ \ \ }\textcolor{comment}{//\ 帧尾}}
\DoxyCodeLine{00022\ \textcolor{preprocessor}{\#define\ CAN\_COMM\_OFFSET\_BYTES\ 4\ \ }\textcolor{comment}{//\ 's'+\ datalen\ +\ 'e'\ +\ crc8}}
\DoxyCodeLine{00023\ }
\DoxyCodeLine{00024\ \textcolor{preprocessor}{\#pragma\ pack(1)}}
\DoxyCodeLine{00025\ \textcolor{comment}{/*\ CAN\ comm\ 结构体,\ 拥有CAN\ comm的app应该包含一个CAN\ comm指针\ */}}
\DoxyCodeLine{00026\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct}}
\DoxyCodeLine{00027\ \{}
\DoxyCodeLine{00028\ \ \ \ \ CANInstance\ *can\_ins;}
\DoxyCodeLine{00029\ \ \ \ \ \textcolor{comment}{/*\ 发送部分\ */}}
\DoxyCodeLine{00030\ \ \ \ \ uint8\_t\ send\_data\_len;\ \textcolor{comment}{//\ 发送数据长度}}
\DoxyCodeLine{00031\ \ \ \ \ uint8\_t\ send\_buf\_len;\ \ \textcolor{comment}{//\ 发送缓冲区长度,为发送数据长度+帧头单包数据长度帧尾以及校验和(4)}}
\DoxyCodeLine{00032\ \ \ \ \ uint8\_t\ raw\_sendbuf[CAN\_COMM\_MAX\_BUFFSIZE\ +\ CAN\_COMM\_OFFSET\_BYTES];\ \textcolor{comment}{//\ 额外4个bytes保存帧头帧尾和校验和}}
\DoxyCodeLine{00033\ \ \ \ \ \textcolor{comment}{/*\ 接收部分\ */}}
\DoxyCodeLine{00034\ \ \ \ \ uint8\_t\ recv\_data\_len;\ \textcolor{comment}{//\ 接收数据长度}}
\DoxyCodeLine{00035\ \ \ \ \ uint8\_t\ recv\_buf\_len;\ \ \textcolor{comment}{//\ 接收缓冲区长度,为接收数据长度+帧头单包数据长度帧尾以及校验和(4)}}
\DoxyCodeLine{00036\ \ \ \ \ uint8\_t\ raw\_recvbuf[CAN\_COMM\_MAX\_BUFFSIZE\ +\ CAN\_COMM\_OFFSET\_BYTES];\ \textcolor{comment}{//\ 额外4个bytes保存帧头帧尾和校验和}}
\DoxyCodeLine{00037\ \ \ \ \ uint8\_t\ unpacked\_recv\_data[CAN\_COMM\_MAX\_BUFFSIZE];\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ 解包后的数据,调用CANCommGet()后cast成对应的类型通过指针读取即可}}
\DoxyCodeLine{00038\ \ \ \ \ \textcolor{comment}{/*\ 接收和更新标志位*/}}
\DoxyCodeLine{00039\ \ \ \ \ uint8\_t\ recv\_state;\ \ \ \textcolor{comment}{//\ 接收状态,}}
\DoxyCodeLine{00040\ \ \ \ \ uint8\_t\ cur\_recv\_len;\ \textcolor{comment}{//\ 当前已经接收到的数据长度(包括帧头帧尾datalen和校验和)}}
\DoxyCodeLine{00041\ \ \ \ \ uint8\_t\ update\_flag;\ \ \textcolor{comment}{//\ 数据更新标志位,当接收到新数据时,会将此标志位置1,调用CANCommGet()后会将此标志位置0}}
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00043\ \ \ \ \ DaemonInstance*\ comm\_daemon;}
\DoxyCodeLine{00044\ \}\ \mbox{\hyperlink{struct_c_a_n_comm_instance}{CANCommInstance}};}
\DoxyCodeLine{00045\ \textcolor{preprocessor}{\#pragma\ pack()}}
\DoxyCodeLine{00046\ }
\DoxyCodeLine{00047\ \textcolor{comment}{/*\ CAN\ comm\ 初始化结构体\ */}}
\DoxyCodeLine{00048\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct}}
\DoxyCodeLine{00049\ \{}
\DoxyCodeLine{00050\ \ \ \ \ \mbox{\hyperlink{struct_c_a_n___init___config__s}{CAN\_Init\_Config\_s}}\ can\_config;\ \textcolor{comment}{//\ CAN初始化结构体}}
\DoxyCodeLine{00051\ \ \ \ \ uint8\_t\ send\_data\_len;\ \ \ \ \ \ \ \ \textcolor{comment}{//\ 发送数据长度}}
\DoxyCodeLine{00052\ \ \ \ \ uint8\_t\ recv\_data\_len;\ \ \ \ \ \ \ \ \textcolor{comment}{//\ 接收数据长度}}
\DoxyCodeLine{00053\ }
\DoxyCodeLine{00054\ \ \ \ \ uint16\_t\ daemon\_count;\ \textcolor{comment}{//\ 守护进程计数,用于初始化守护进程}}
\DoxyCodeLine{00055\ \}\ \mbox{\hyperlink{struct_c_a_n_comm___init___config__s}{CANComm\_Init\_Config\_s}};}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00063\ \mbox{\hyperlink{struct_c_a_n_comm_instance}{CANCommInstance}}\ *\mbox{\hyperlink{can__comm_8h_a611c266bef866f02414a73b7d5584f86}{CANCommInit}}(\mbox{\hyperlink{struct_c_a_n_comm___init___config__s}{CANComm\_Init\_Config\_s}}\ *comm\_config);}
\DoxyCodeLine{00064\ }
\DoxyCodeLine{00071\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{can__comm_8h_a034f32d1bf2deb6386ed06690f41a7a6}{CANCommSend}}(\mbox{\hyperlink{struct_c_a_n_comm_instance}{CANCommInstance}}\ *instance,\ uint8\_t\ *data);}
\DoxyCodeLine{00072\ }
\DoxyCodeLine{00082\ \textcolor{keywordtype}{void}\ *\mbox{\hyperlink{can__comm_8h_ac3cf44018acff09b65450d846df10b6d}{CANCommGet}}(\mbox{\hyperlink{struct_c_a_n_comm_instance}{CANCommInstance}}\ *instance);}
\DoxyCodeLine{00083\ }
\DoxyCodeLine{00090\ uint8\_t\ \mbox{\hyperlink{can__comm_8h_a3e10f1654f1cea65cdb5f1e37912140d}{CANCommIsOnline}}(\mbox{\hyperlink{struct_c_a_n_comm_instance}{CANCommInstance}}\ *instance);}
\DoxyCodeLine{00091\ }
\DoxyCodeLine{00092\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//\ !CAN\_COMM\_H}}

\end{DoxyCode}
